package com.szh.zx.gaoDingJavaBook.yitu.one;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class HashMap1 {
	public static void main(String[] args) {
		HashMap<String, Integer> map = new HashMap<>();
		map.put("ddd", 1);
		map.put("ddd1", 1);
		map.put("ddd2", 1);
		map.put("ddd3", 1);
		System.out.println(map);
//		1.拿到key 根据key拿到val 效率低
		Set<String> set = map.keySet();
		for (String key : set) {
			Integer val = map.get(key);
			System.out.println(key + "->" + val);
		}
		System.out.println("==============================");
//		2. 只拿 values
		Collection<Integer> values = map.values();
		for (Integer value : values) {
			System.out.println(value);
		}
//		3. 直接遍历
		Set<Map.Entry<String, Integer>> entrySet = map.entrySet();
		for (Map.Entry<String, Integer> entry : entrySet) {
			System.out.println(entry);
		}
	}
}
